var $strAcademicoPensumUrl = "admin_academico_pensum_data.php";
var $strAcademicoPensumForm = "frmAcademicoPensum";
function fntAcademicoPensumContenido() {
    
    var objInterface = $("#divAcademicoPensumContenido");
    objInterface.html("");
    $.ajax({

        type: "POST",
        data: $("#"+$strAcademicoPensumForm).serialize(),
        url: $strAcademicoPensumUrl+"?operation=contenido",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            fntCloseDialogCargando();
            
        },
        error:function() {
            fntCloseDialogCargando();
        }

    });
    
}
function fntAcademicoPensumReporte() {
    
    var objInterface = $("#divAcademicoPensumReporte");
    objInterface.html("");
    $.ajax({

        type: "GET",
        url: $strAcademicoPensumUrl+"?operation=reporte",
        beforeSend:function() {
            //fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            //fntCloseDialogCargando();
        },
        error:function() {
            //fntCloseDialogCargando();
        }

    });
    
}
function fntAcademicoPensumValidar() {
    strError = "";
    boolReturn = true;
    
    if( $("input[name='txtAcademicoPensum_codigo']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese codigo";
        boolReturn = false;
    }    
    if( $("input[name='txtAcademicoPensum_VIGENCIA-INICIAL']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese vigencia inicial";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoPensum_VIGENCIA-FINAL']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese vigencia final";
        boolReturn = false;
    }
    
    if( !boolReturn )
        alert(strError);
        
    return boolReturn;
    
}
function fntAcademicoPensumGrabar() {
    
    var objInterface = $("#divAcademicoPensumOperaciones");
    objInterface.html("");
    if( fntAcademicoPensumValidar() ) {
        $.ajax({

            type: "POST",
            data: $("#"+$strAcademicoPensumForm).serialize(),
            url: $strAcademicoPensumUrl+"?operation=s",
            beforeSend:function() {
                fntOpenDialogCargando();
            },
            success:function(data) {
                objInterface.html(data);
                fntCloseDialogCargando();
                fntAcademicoPensumContenido();
                fntAcademicoPensumReporte();
            },
            error:function() {
                fntCloseDialogCargando();
            }

        });
    }
    
}
function fntAcademicoPensumNuevo() {
    
    var objInterface = $("#divAcademicoPensumOperaciones");
    objInterface.html("");
    $("input[name='hdnAcademicoPensum_Id']").val("");
    fntAcademicoPensumContenido();
    
}
function fntAcademicoPensumMateriaAgregar() {
    
    objMateria = $("#sltAcademicoPensumMaterias");
    
    objDiv = $("#divAcademicoPensumMaterias");
    if( objMateria.val() > 0 ) {
        strHtml = '';
        strHtml += '<div style="width: 482px; height: 25px; float: left; line-height: 25px; vertical-align: middle; border-bottom: 1px solid black;">&nbsp;&nbsp;&nbsp;&nbsp;'+$("#sltAcademicoPensumMaterias option:selected").text()+'</div>';
        strHtml += '<input type="hidden" name="hdnAcademicoPensumD_'+objMateria.val()+'" value="'+objMateria.val()+'">';
        
        objDiv.append(strHtml);
    }
    
}

$(function() {
    $("#btnAcademicoPensumNuevo").click( function () {
        fntAcademicoPensumNuevo();
    });
    $("#btnAcademicoPensumGrabar").click( function () {
        fntAcademicoPensumGrabar();
    });
    fntAcademicoPensumContenido();
    fntAcademicoPensumReporte();
});